﻿using System;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Xml;
using System.Collections.Generic;

namespace YAWD.Utils
{
    class rssReader
    {
        public static SyndicationItem read(Uri site)
        {
            SyndicationItem objVersion = null;
            XmlReader reader = null;
            try
            {
                reader = XmlReader.Create(site.ToString());
                SyndicationFeed feed = SyndicationFeed.Load(reader);

                if (feed != null)
                    foreach (SyndicationItem item in feed.Items)
                    {
                        objVersion = item;
                        break;
                    }

                return objVersion;
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

        }
        public static IList<SyndicationItem> getAll(Uri site)
        {
            XmlReader reader = null;
            try
            {
                reader = XmlReader.Create(site.ToString());
                SyndicationFeed feed = SyndicationFeed.Load(reader);

                if (feed != null) return feed.Items.ToList();
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            return null;
        }
    }
}
